import cn.sh.yhk.Application;
import cn.sh.yhk.configure.elasticsearch.EsRestService;
import com.frameworkset.common.poolman.util.SQLUtil;
import org.frameworkset.elasticsearch.ElasticSearchHelper;
import org.frameworkset.elasticsearch.client.ClientInterface;
import org.frameworkset.elasticsearch.entity.ESDatas;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created with IDEA
 * author:Yhk
 * Date:2019/6/19
 * Time:2:56 PM
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class EsJdbc {
    @Resource
    EsRestService esRestService;

    public void initDBSource() {
        SQLUtil.startPool("es",//ES数据源名称
                "org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcDriver",//ES jdbc驱动
                "jdbc:es://http://172.28.97.187:9200/timezone=UTC&page.size=250",//es链接串
                "elastic", "changeme",//es x-pack账号和口令
                "SHOW tables 'dbclob%'" //数据源连接校验sql
        );
    }

    @Test
    public void testESSQL() {
        String json = esRestService.restClient().executeHttp("/_xpack/sql?format=txt",
                "{\"query\": \"SELECT * FROM abc-2019.06\"}",
                ClientInterface.HTTP_POST);
    }

}
